{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4cf557d3",
   "metadata": {},
   "source": [
    "------------\n",
    "* 日期：2023-3-24 \\ week5（周五）\n",
    "* 课程：api\n",
    "* 记录人：zhou\n",
    "------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e9c6b4b",
   "metadata": {},
   "source": [
    "## Face++\n",
    "\n",
    "> API Key:ASqrtQf5RRZ72YUVUcLcT7vjermE1hjH\n",
    "\n",
    "> API Secret:S7bXnprbdjmKDL6H6K1ieHr2RvQR4XhB"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9743c8f",
   "metadata": {},
   "source": [
    "## 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "68a96bd0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679662157,c706259c-3bda-4c0c-bc02-eb38014ff9e0', 'time_used': 715, 'faces': [{'face_token': 'a71b1896c7d968840cbdbce64bd00908', 'face_rectangle': {'top': 801, 'left': 753, 'width': 637, 'height': 637}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 19}, 'emotion': {'anger': 0.469, 'disgust': 0.017, 'fear': 0.233, 'happiness': 0.019, 'neutral': 16.859, 'sadness': 82.307, 'surprise': 0.096}, 'beauty': {'male_score': 82.998, 'female_score': 84.29}}}], 'image_id': 'IFnoKLh9Z5rU1XnTONW/cA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('jjy.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"api_key\":\"ASqrtQf5RRZ72YUVUcLcT7vjermE1hjH\",\n",
    "    \"api_secret\":\"S7bXnprbdjmKDL6H6K1ieHr2RvQR4XhB\",\n",
    "    \"image_base64\":img,\n",
    "    \"return_attributes\":\"gender,age,emotion,beauty\"\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f143d0c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
